/*
* 资产功能
* */
import React, {Component} from "react";
import {observer, inject} from "mobx-react";
import {withRouter} from "react-router-dom";
import {Tabs, Tools} from "weaver-mobile";
import {ListAdvanced} from "weaver-mobile-page";
import {getUrlParams} from "../../util"

const getLabel = Tools.getLabel;

const tabs = [
    {
        title: getLabel(1209, "我的资产"),
        index: 0
    },
    {
        title: getLabel(390209, "全部资产"),
        index: 1
    },
]
@inject("assetStore")
@withRouter
@observer
export default class Asset extends Component {
    componentDidMount() {
        const {hrmid} = getUrlParams(this.props.location.search)
        this.props.assetStore.init(hrmid || "");
    }

    render() {
        const {history, assetStore} = this.props;
        const {
            assetListAll, assetListMine, showCheck, selectedTabIndex,
            dataFetchOptions, conditionFetchOptions, dataFetchOptionsMine
        } = assetStore;
        const {onSearch, onTabChange} = assetStore;
        return (<div>
            <Tabs tabs={tabs}
                  initialPage={0}
                  page={selectedTabIndex}
                  prerenderingSiblingsNumber={0}
                  swipeable={false}     //是否可以滑动内容切换
                  useOnPan={false}      //使用跟手滚动
                  animated={true}       //动画效果
                  onChange={(tab) => {
                      onTabChange(tab.index)
                  }}
            />
            <ListAdvanced
                store={selectedTabIndex === 1 ? assetListAll : assetListMine}
                hasAdvanceSerach={selectedTabIndex === 1}
                rowKey="id"
                searchKey="name"
                dataFetchOptions={selectedTabIndex === 1 ? dataFetchOptions : dataFetchOptionsMine}
                conditionFetchOptions={conditionFetchOptions}
                showCheck={showCheck}
                onSearch={onSearch}
                onRowClick={(item) => history.push("/assetInfo/infoCard/" + item.id)}
                heightSpace={window.getThemeVars ? window.getThemeVars()["tab-bar-height"] : 50}
                useBodyScroll={false}
            />
        </div>)
    }
}
